/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import Taro, { Component } from '@tarojs/taro'
import { AtSwipeAction } from "taro-ui"

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton, CColumn } from '../../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Http, Toast } from '../../../library/func';
import Icon from '../../../project/style/icon';
import time from '../../../project/func/util'

/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class HelpList extends Component {

	/*------------------------------------------------------------------------------------
	 * 初始化
	 *-----------------------------------------------------------------------------------*/
	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			messageList:[
				{set_head:'http://image.mod.hesq.com.cn/rushbuy/assets/20181113/message.jpg',set_name:'每日一达',set_content:'您好，很高兴为你服务埃及四季酒店是否合适袋还是覅爱兑换覅',set_time:'1542093692'},
				{set_head:'http://image.mod.hesq.com.cn/rushbuy/assets/20181113/message.jpg',set_name:'每日一达',set_content:'您好，很高兴为你服务埃及四季酒店是否合适袋还是覅爱兑换覅',set_time:'1542093692'}
			]
			
		}
	}

	/*------------------------------------------------------------------------------------
	 * 生命周期
	 *-----------------------------------------------------------------------------------*/
	// didMount
	componentDidMount() {

	}
	
	/*------------------------------------------------------------------------------------
	 * 事件处理
	 *-----------------------------------------------------------------------------------*/
    // onRedirect 跳转至详情页
    onRedirect = (url, e)=> {
        wx.redirectTo({
            url: url
        })
    }

	/*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/
	 // 轻提示
    onToast = ()=> {
        console.log('暂未开启此功能')
		// Toast.text('测试一下');
    }
	// 删除消息
	deleteMsg = (index,event) => {
		let nowList = this.state.messageList;
		let newList = nowList;
		
		let a = newList.splice(index,1)

		this.setState({
			messageList: newList
		})
	}

	// 关闭其他条目
	closeSthing = index => {
		const list = this.state.messageList.map((item, key) => {
			item.isClose = key !== index
			return item
		})
		this.setState({
			messageList:list
		})
	}

	config = {
        navigationBarTitleText: '消息',
        navigationBarBackgroundColor: '#dd2f3c',
        navigationBarTextStyle: '#fff'
    }

	/*------------------------------------------------------------------------------------
	 * 渲染
	 *-----------------------------------------------------------------------------------*/
	render () {
		return (
			<CPage>
				<CContent>
					
					{/* 帮助列表 */}
					<CColumn bg='#fff' >
						{/* 列表循环 */}
						{this.state.messageList.map( (item,i) => {
							return (
								<AtSwipeAction style='width:100%'
									autoClose
									key={i}
									onOpened={this.closeSthing.bind(this,i)}
									isClose={item.isClose}
									options={item.options}
									onClick={this.deleteMsg.bind(this,i)} options={[
										{
											text: '删除',
											style: {
											backgroundColor: '#FF4949'
											}
										}
									]}
								>
									<CBetween className='normal' bb='1 solid #e6e6e6' py='16' mx='20' onClick={this.onToast}>
										<CItemX class='w1' >
											<CImage w='130' h='130' df src={item.set_head}></CImage>
											<CItemY pl='10' x='left' class='f1' style='overflow:hidden;'>
												<CLine size='32' color='#3e3e3e' mt='8'>{item.set_name}</CLine>
												<CLine color='#b3b3b3' x='right' size='20'>{time.formatTime(item.set_time, 'h:m')}</CLine>
												<CLine color='#b3b3b3' class='textOver' size='24' mt='8'>{item.set_content}</CLine>
											</CItemY>
										</CItemX>
									</CBetween>
								</AtSwipeAction>
							)
						})}
					</CColumn>

				</CContent>
			</CPage>
		)
	}
}


